package com.hzcx.app.simplechat.ui.group;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;

import com.hzcx.app.simplechat.api.BaseObserver;
import com.hzcx.app.simplechat.base.BaseEmptyBean;
import com.hzcx.app.simplechat.model.GroupModel;
import com.hzcx.app.simplechat.ui.friend.adapter.NewFriendAdapter;
import com.hzcx.app.simplechat.ui.friend.bean.FriendCityBean;
import com.hzcx.app.simplechat.ui.publicui.PublicConfirmDialog;

import java.util.ArrayList;


public class GroupOwnerTransferActivity extends ChatGroupDeleteMemberActivity {

    @Override
    public void initView() {
        tvTitle.setText("选择新群主");
        tvTitleRight.setVisibility(View.GONE);
        tvNext.setVisibility(View.GONE);
        groupID = getIntent().getStringExtra(GroupCreateActivityGroupID);

        friendData = new ArrayList<>();
        friendAdapter = new NewFriendAdapter(friendData, 0);
        rvFriend.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
        rvFriend.setAdapter(friendAdapter);

        sideBar.setOverlay(tvOverlay);

        sideBar.setOnLetterChangedListener(this);

        friendAdapter.setOnFriendListItemOnClickListener((headerPos, contentPos, id, bean) -> {
            showConfirmDialog(bean);
        });
        sideBar.setVisibility(View.GONE);
    }

    /**
     *  清除聊天记录
     */
    private void showConfirmDialog(FriendCityBean bean) {
        String content = "将群主转让给" + (bean.getRemarks_name() != null ? bean.getNickname() : bean.getNickname()) + "?";
        showConfirmDialog("", content, null, new PublicConfirmDialog.OnPublicConfirmClickListener() {
            @Override
            public void publicConfirm() {
                GroupModel.transferAdminGroup(GroupOwnerTransferActivity.this, groupID, String.valueOf(bean.getMember_id()), new BaseObserver<BaseEmptyBean>() {
                    @Override
                    protected void onSuccess(BaseEmptyBean data) {
                        finish();
                    }
                });
            }
        });
    }

}